home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 035a / broadcas.zip / BROADCAS.PAS
Pascal/Delphi Source File  |  1991-04-11  |  4KB  |  169 lines

  1. {
  2.    This program will create two modaless dialog boxes and will
  3.    allow only one Dialog2 dialog to be created at any time.
  4.  
  5.    Additionally, it will demonstrate how to broadcast messages to
  6.    background windows and update information without changing
  7.    the selected dialog.
  8.  
  9. }
  10. {$X+}
  11.  
  12. Program DialogCommunication;
  13.  
  14. uses Objects, Drivers, Views, Menus, Dialogs, App, Crt;
  15. const
  16.   cmDialog1 = 100;
  17.   cmDialog2 = 101;
  18.   cmDialog1Button = 200;
  19.   cmDialog2Button = 201;
  20.  
  21. type
  22.  
  23.  PHelloApp = ^THelloApp;
  24.   THelloApp = object(TApplication)
  25.     procedure MakeDialog;
  26.     procedure HandleEvent(var Event: TEvent); virtual;
  27.     procedure InitMenuBar; virtual;
  28.     procedure InitStatusLine; virtual;
  29.   end;
  30.  
  31.   PMyDialog1 = ^TMyDialog1;
  32.   TMyDialog1 = object(TDialog)
  33.     procedure MakeDialog2;
  34.     procedure HandleEvent(var Event:TEvent); virtual;
  35.   end;
  36.  
  37.   PMyDialog2 = ^TMyDialog2;
  38.   TMyDialog2 = object(TMyDialog1)
  39.     procedure HandleEvent(var Event:TEvent); virtual;
  40.   end;
  41.  
  42. procedure TMyDialog1.HandleEvent(var Event: TEvent);
  43. var
  44.   AreYouThere: PView;
  45. begin
  46.   TDialog.HandleEvent(Event);
  47.   if Event.What = evCommand then
  48.     begin
  49.       case Event.Command of
  50.          cmDialog1Button:
  51.            begin
  52.              AreYouThere:= Message(DeskTop, evBroadcast, cmDialog2, nil);
  53.              if AreYouThere = nil then
  54.                 MakeDialog2
  55.               else
  56.                 ClearEvent(Event);
  57.            end
  58.       else
  59.         Exit;
  60.       end;
  61.         ClearEvent(Event);
  62.     end;
  63. end;
  64.  
  65. procedure TMyDialog1.MakeDialog2;
  66. var
  67.   Dialog2: PMyDialog2;
  68.   R: TRect;
  69.   Button: PButton;
  70. begin
  71.   R.Assign(1,1,40,20);
  72.   Dialog2:= New(PMyDialog2, init(R,'Dialog2'));
  73.   R.Assign(10,10,20,12);
  74.   Button:= New(PButton,Init(R,'Beep', cmDialog2Button, bfdefault));
  75.   Dialog2^.Insert(Button);
  76.   DeskTop^.Insert(Dialog2);
  77. end;
  78.  
  79. procedure TMyDialog2.HandleEvent(var Event: TEvent);
  80. begin
  81.   case Event.Command of
  82.     cmDialog2: begin
  83.                  sound(2000); delay(10); nosound;
  84.                  Title:=newstr('Hello world');
  85.                  ReDraw;
  86.                  ClearEvent(Event);
  87.                end;
  88.   end;
  89.   TDialog.HandleEvent(Event);
  90.   if Event.What = evCommand then
  91.     begin
  92.       case Event.Command of
  93.          cmDialog2Button: begin
  94.                             Sound(1000); delay(100); NoSound;
  95.                           end;
  96.       else
  97.         Exit;
  98.       end;
  99.         ClearEvent(Event);
  100.     end;
  101. end;
  102.  
  103. { THelloApp }
  104.  
  105. procedure THelloApp.MakeDialog;
  106. var
  107.   R:TRect;
  108.   Button1: PButton;
  109.   Dialog1: PMyDialog1;
  110. begin
  111.   R.Assign(25, 5, 65, 16);
  112.   Dialog1:= New(PMyDialog1, init(R,'Dialog1'));
  113.   R.Assign(16, 8, 38, 10);
  114.   Button1:= New(PButton, Init(R,'Call Dialog2', cmDialog1Button, bfDefault));
  115.   Dialog1^.Insert(Button1);
  116.   DeskTop^.Insert(Dialog1);
  117. end;
  118.  
  119. procedure THelloApp.HandleEvent(var Event: TEvent);
  120. begin
  121.   TApplication.HandleEvent(Event);
  122.   if Event.What = evCommand then
  123.     begin
  124.       case Event.Command of
  125.          cmDialog1:begin
  126.                      MakeDialog;
  127.                    end;
  128.       else
  129.         Exit;
  130.       end;
  131.         ClearEvent(Event);
  132.      end;
  133. end;
  134.  
  135. procedure THelloApp.InitMenuBar;
  136. var
  137.   R: TRect;
  138. begin
  139.   GetExtent(R);
  140.   R.B.Y := R.A.Y + 1;
  141.   MenuBar := New(PMenuBar, Init(R, NewMenu(
  142.     NewSubMenu('~O~pen Dialogs', hcNoContext, NewMenu(
  143.       NewItem('~D~ialog1','', 0, cmDialog1, hcNoContext,
  144.       NewLine(
  145.       NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit,
  146.         hcNoContext, nil)))), nil))));
  147. end;
  148.  
  149. procedure THelloApp.InitStatusLine;
  150. var
  151.   R: TRect;
  152. begin
  153.   GetExtent(R);
  154.   R.A.Y := R.B.Y-1;
  155.   StatusLine := New(PStatusLine, Init(R,
  156.     NewStatusDef(0, $FFFF,
  157.       NewStatusKey('', kbF10, cmMenu,
  158.       NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit, nil)), nil)));
  159. end;
  160.  
  161. var
  162.   HelloWorld: THelloApp;
  163.  
  164. begin
  165.   HelloWorld.Init;
  166.   HelloWorld.Run;
  167.   HelloWorld.Done;
  168. end.
  169.